package LuoGu;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

public class P1241 {
    public static void main(String[] args) throws IOException {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        String s=br.readLine();
        br.close();
        boolean[] isHave=new boolean[s.length()];
        Arrays.fill(isHave,false);
        StringBuilder sb=new StringBuilder();
        for (int i = 0; i < s.length(); i++) {
            if(s.charAt(i)==')') {
                if(i>0){
                    if (s.charAt(i-1) == '(' && !isHave[i-1]) {
                        isHave[i-1] = true;
                        isHave[i]=true;
                    }
                }
            }if(s.charAt(i)==']') {
                if(i>0){
                    if (s.charAt(i-1) == '[' && !isHave[i-1]) {
                        isHave[i-1] = true;
                        isHave[i]=true;
                    }
                }
            }
        }
        for (int i = 0; i < isHave.length; i++) {
            if(i>0&&isHave[i]&&!isHave[i-1]){
                int left=i;
                int right=i;
                while(right<isHave.length-1&&isHave[right+1]){
                    right++;
                }
                while(true){
                    if(left>0&&right<isHave.length-1){
                        if(s.charAt(left-1)=='('&&s.charAt(right+1)==')'){
                            left--;
                            right++;
                            isHave[left]=true;
                            isHave[right]=true;
                        }else if(s.charAt(left-1)=='['&&s.charAt(right+1)==']'){
                            left--;
                            right++;
                            isHave[left]=true;
                            isHave[right]=true;
                        }else{
                            break;
                        }
                    }else{
                        break;
                    }
                }
            }
        }
        for (int j = 0; j < isHave.length; j++) {
             if(isHave[j]){
                 sb.append(s.charAt(j));
             }else{
                 if(s.charAt(j)=='('||s.charAt(j)==')'){
                     sb.append('(').append(")");
                 }else{
                     sb.append('[').append(']');
                 }
             }
        }
        System.out.print(sb.toString());
    }
}
